package com.example.switchcontrolplatform.result;

import com.example.switchcontrolplatform.enumeration.PricingStatus;
import com.example.switchcontrolplatform.item.DiscountDetail;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class PricingResult {

	private BigDecimal originalAmount; // 原始价格
	private BigDecimal finalAmount; // 最终价格
	private BigDecimal totalDiscount; // 优惠金额
	private List<DiscountDetail> discountDetails; // 优惠详情
	private List<String> appliedStrategies; // 应用的策略
	private PricingStatus status; // 定价结果状态
	private String errorMessage; // 错误信息

	public PricingResult() {
		this.discountDetails = new ArrayList<>();
		this.appliedStrategies = new ArrayList<>();
		this.status = PricingStatus.SUCCESS;
	}

	public static class Builder {
		private PricingResult result = new PricingResult();

		public Builder originalAmount(BigDecimal amount) {
			result.originalAmount = amount;
			return this;
		}

		public Builder finalAmount(BigDecimal amount) {
			result.finalAmount = amount;
			return this;
		}

		public Builder addDiscountDetail(DiscountDetail detail) {
			result.discountDetails.add(detail);
			return this;
		}

		public Builder addAppliedStrategy(String strategy) {
			result.appliedStrategies.add(strategy);
			return this;
		}

		public PricingResult build() {
			if (result.originalAmount != null && result.finalAmount != null) {
				result.totalDiscount = result.originalAmount.subtract(result.finalAmount);
			}
			return result;
		}
	}
}
